/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 enum_operations.h

	$Header: /heroes4/enum_operations.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( ENUM_OPERATIONS_H_INCLUDED )
#define ENUM_OPERATIONS_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// -------------------------------------------------------------
// Functions for simplifying arithemetic operations on enum
// variables.
// -------------------------------------------------------------

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_incr( t_enum & enum_arg )
{
	enum_arg = static_cast< t_enum >( enum_arg + 1 );
	return enum_arg;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_incr( t_enum & enum_arg, int diff )
{
	enum_arg = static_cast< t_enum >( enum_arg + diff );
	return enum_arg;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_post_incr( t_enum & enum_arg )
{
	t_enum old_val = enum_arg;
	enum_incr( enum_arg );
	return old_val;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_post_incr( t_enum & enum_arg, int diff )
{
	t_enum old_val = enum_arg;
	enum_incr( enum_arg, diff );
	return old_val;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_decr( t_enum & enum_arg )
{
	enum_arg = static_cast< t_enum >( enum_arg - 1 );
	return enum_arg;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_decr( t_enum & enum_arg, int diff )
{
	enum_arg = static_cast< t_enum >( enum_arg - diff );
	return enum_arg;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_post_decr( t_enum & enum_arg )
{
	t_enum old_val = enum_arg;
	enum_decr( enum_arg );
	return old_val;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_post_decr( t_enum & enum_arg, int diff )
{
	t_enum old_val = enum_arg;
	enum_decr( enum_arg, diff );
	return old_val;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_add( t_enum left, int right )
{
	t_enum result = left;
	enum_incr( result, right );
	return result;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_add( int left, t_enum right )
{
	return enum_add( right, left );
}

// -------------------------------------------------------------
// -------------------------------------------------------------
template < typename t_enum >
inline t_enum enum_subtract( t_enum left, int right )
{
	t_enum result = left;
	enum_decr( result, right );
	return result;
}

#endif // !defined( ENUM_OPERATIONS_H_INCLUDED )
